<template>
  <div class="app-container">
    <el-form  class="formWidth" :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="求职类型" prop="interviewType">
        <el-select v-model="queryParams.interviewType" placeholder="请选择求职类型" clearable size="small">
          <el-option
            v-for="dict in interviewTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="简历状态" prop="resumeStatus">
        <el-select v-model="queryParams.resumeStatus" placeholder="请选择简历状态" clearable size="small">
          <el-option
            v-for="dict in resumeStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['enterprise:interview:add']"
        >投递简历</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['enterprise:interview:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['enterprise:interview:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['enterprise:interview:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="interviewList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="求职信息ID" align="center" prop="interviewId" /> -->
      <el-table-column label="求职者姓名" show-overflow-tooltip align="center" prop="sresume.username" />
      <el-table-column label="用工单位名称" show-overflow-tooltip align="center" prop="scompany.companyName" />
      <el-table-column label="岗位名称" show-overflow-tooltip align="center" prop="sjob.jobName" />
      <el-table-column label="求职类型" show-overflow-tooltip align="center" prop="interviewType" :formatter="interviewTypeFormat" />
      <el-table-column label="简历状态" show-overflow-tooltip align="center" prop="resumeStatus" :formatter="resumeStatusFormat" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleLook(scope.row)"
            v-hasPermi="['enterprise:interview:edit']"
          >查看简历</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['enterprise:interview:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="简历" prop="resumeId">
            <el-select v-model="form.resumeId" placeholder="请选择投递人">
              <el-option
                v-for="dict in resumeOptions"
                :key="dict.resumeId"
                :label="dict.username"
                :value="parseInt(dict.resumeId)"
              ></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="用工单位" prop="companyId">
            <el-select v-model="form.companyId" @change="changeCompany" placeholder="请选择公司">
              <el-option
                v-for="dict in companyOptions"
                :key="dict.companyId"
                :label="dict.companyName"
                :value="parseInt(dict.companyId)"
              ></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="岗位" prop="jobId">
            <el-select v-model="form.jobId" placeholder="请选择岗位">
              <el-option
                v-for="dict in jobOptions"
                :key="dict.jobId"
                :label="dict.jobName"
                :value="parseInt(dict.jobId)"
              ></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="求职类型" prop="interviewType">
          <el-select v-model="form.interviewType" placeholder="请选择求职类型">
            <el-option
              v-for="dict in interviewTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="简历状态" prop="resumeStatus">
          <el-select v-model="form.resumeStatus" placeholder="请选择简历状态">
            <el-option
              v-for="dict in resumeStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  <!-- 查看简历对话框 -->
  <el-dialog :title="titleResume" :visible.sync="openResume" width="800px" append-to-body>
      <el-form ref="formResume" :model="formResume" label-width="120px" size="mini">
        <el-row>
        <span>| </span><span>基本信息</span>
        <el-divider></el-divider>  
        <div style="margin:0 auto">
          <el-col :span="18">
            <el-row>
            </el-row>
            <el-row style="margin-left:-50px;margin-bottom:20px">
                <!-- <el-form-item label="姓名" prop="companyId">
                  <el-input style="width:193px" v-model="formResume.username" placeholder="请输入姓名" disabled/>
                </el-form-item>
                <el-form-item label="性别" prop="companyId">
                  <el-input style="width:193px" v-model="formResume.sex" placeholder="请输入性别" disabled/>
                </el-form-item>
                <el-form-item label="年龄" prop="companyId">
                  <el-input style="width:193px" v-model="formResume.age" placeholder="请输入年龄" disabled/>
                </el-form-item> -->
              <div class="introduction">
                <div class="name">{{formResume.username}}</div>
                <div class="info">
                  <div class="experience">{{formResume.descriptions}}</div> 
                  <div class="notes">
                    <ul>
                      <li v-for="(note,ind) in formResume.occupationalLabelArr" :key="ind">{{note}}</li>
                    </ul>
                  </div>
                </div>
              </div>
            </el-row>   
          </el-col>
          <el-col :span="6">
            <div ><img v-bind:src="options.img" style="height: 150px;width: 150px" /></div>
          </el-col>
        </div>
        </el-row>
        <el-row>
        <div>
          <span>| </span><span>教育背景</span>
          <el-divider></el-divider>  
        </div>
        <div style="width: 60%;margin:0 auto">
          <!-- <el-form-item label="公司名称" prop="companyId">
            <el-input style="width:193px" v-model="formResume.jobName" placeholder="请输入岗位名称" />
          </el-form-item>
          <el-form-item label="岗位名称" prop="jobName">
            <el-input style="width:193px" v-model="formResume.jobName" placeholder="请输入岗位名称" />
          </el-form-item>
          <el-form-item label="岗位类别" prop="jobType">
            <el-input style="width:193px" v-model="formResume.jobName" placeholder="请输入岗位名称" />
          </el-form-item>
          <el-form-item label="学历要求" prop="education">
            <el-input style="width:193px" v-model="formResume.jobName" placeholder="请输入岗位名称" />
          </el-form-item>
          <el-form-item label="招聘人数" prop="jobCnt">
            <el-input-number v-model="formResume.jobCnt" :min="1" :max="500" label="请输入招聘人数"></el-input-number>
          </el-form-item>
          <el-form-item label="薪资类型" prop="salaryType">
            <el-input style="width:193px" v-model="formResume.jobName" placeholder="请输入岗位名称" />
          </el-form-item>
          <el-form-item label="薪资范围" prop="salary">
            <el-col :span="10">
              <el-input v-model="formResume.salaryMin" placeholder="最少薪资" style="width: 90%;"/>
            </el-col>
            <el-col :span="2">至</el-col>
            <el-col :span="10">
              <el-input v-model="formResume.salaryMax" placeholder="最高薪资" style="width: 90%;"/>
            </el-col>
            元
          </el-form-item> -->
        </div>
        </el-row>
        <div>
            <span>| </span><span>工作经验</span>
            <el-divider></el-divider>
        </div>
        <div style="width: 70%;margin:0 auto">
          <!-- <el-form-item label="所在省市区" prop="area">
            <el-col :span="7">
              <el-input style="width:193px" v-model="formResume.jobName" placeholder="请输入岗位名称" />
            </el-col>
            <el-col :span="1" style="display:inline-block;text-align:center;"><span >-</span></el-col>
            <el-col :span="7">
              <el-input style="width:193px" v-model="formResume.jobName" placeholder="请输入岗位名称" />
            </el-col>
            <el-col :span="1" style="display:inline-block;text-align:center;"><span>-</span></el-col>
            <el-col :span="7">
              <el-input style="width:193px" v-model="formResume.jobName" placeholder="请输入岗位名称" />
            </el-col>
          </el-form-item>
          <el-form-item label="工作详细地址" prop="workingAddress">
            <el-input v-model="formResume.workingAddress" placeholder="请输入工作详细地址" />
          </el-form-item>  -->
        </div>
        <div>
            <span>| </span><span>联系方式</span>
            <el-divider></el-divider>
        </div>
        <div style="width: 60%;margin:0 auto">
          <el-form-item label="联系人电话" prop="contactPhoneNo">
            {{formResume.phoneNo}}
          </el-form-item>
        </div>
        <div>
            <span>| </span><span>自我评价</span>
            <el-divider></el-divider>
        </div>
        <div style="width: 60%;margin:0 auto">
          <el-form-item label="自我评价" prop="jobDesc">
            <el-input v-model="formResume.jobDesc" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </div>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancelResume">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改求职信息对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="简历ID" prop="resumeId">
          <el-input v-model="form.resumeId" placeholder="请输入简历ID" />
        </el-form-item>
        <el-form-item label="用工单位ID" prop="companyId">
          <el-input v-model="form.companyId" placeholder="请输入用工单位ID" />
        </el-form-item>
        <el-form-item label="岗位ID" prop="jobId">
          <el-input v-model="form.jobId" placeholder="请输入岗位ID" />
        </el-form-item>
        <el-form-item label="求职类型" prop="interviewType">
          <el-select v-model="form.interviewType" placeholder="请选择求职类型">
            <el-option
              v-for="dict in interviewTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="简历状态" prop="resumeStatus">
          <el-select v-model="form.resumeStatus" placeholder="请选择简历状态">
            <el-option
              v-for="dict in resumeStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import { listInterview, getInterview, delInterview, addInterview, updateInterview, exportInterview } from "@/api/enterprise/interview";
import { getAllCompanysInfo,provinceList,cityList } from "@/api/jobservice/company";
import { getJobInfoByCompanyId } from "@/api/enterprise/position";
import { getAllResume } from "@/api/enterprise/resume";
import store from "@/store";

export default {
  name: "Interview",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 求职信息表格数据
      interviewList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 求职类型字典
      interviewTypeOptions: [],
      // 简历状态字典
      resumeStatusOptions: [],
      // 公司列表
      companyOptions:[],
      //求职者列表
      resumeOptions:[],
      //岗位列表
      jobOptions:[],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        interviewType: null,
        resumeStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      formResume:{},
      titleResume:'',
      openResume:false,
      options: {
        img: '', //裁剪图片的地址
        autoCrop: true, // 是否默认生成截图框
        autoCropWidth: 200, // 默认生成截图框宽度
        autoCropHeight: 200, // 默认生成截图框高度
        fixedBox: true // 固定截图框大小 不允许改变
      },
      allJobArr: [], //初始的所有职位数据
      jobArr: [], // 搜索展示的职位数据
      workExperienceArr: [],
      educationArr: [],
    };
  },
  created() {
    this.getList();
    this.getDicts("s_interview_type").then(response => {
      this.interviewTypeOptions = response.data;
    });
    this.getDicts("s_resume_status").then(response => {
      this.resumeStatusOptions = response.data;
    });
    this.getAllCompanysInfo()
    this.listAllResume()
    console.log(store.getters.avatar)

    this.getDicts("s_job_list").then(response => { //获取岗位
      this.allJobArr = response.data;
      this.jobArr = this.allJobArr
    });
    this.getDicts("s_work_experience").then(response => { //获取岗位
      let work = [{
        dictLabel: '不限',
        dictValue: '',
      }]
      this.workExperienceArr = work.concat(response.data);
    });
    this.getDicts("s_education").then(response => { //获取岗位
      let edu = [{
        dictLabel: '不限',
        dictValue: '',
      }]
      this.educationArr = edu.concat(response.data);
    });

  },
  methods: {
    cancelResume(){
      this.openResume = false
    },
    /** 查看简历 */
    handleLook(row){
      console.log(row)
      this.options.img = process.env.VUE_APP_BASE_API + row.sresume.avatar
      this.formResume = row.sresume
      this.setDesc(this.formResume)
      this.openResume = true;
      this.titleResume = "简历信息";
    },
    setDesc(item){
      console.log(item)
      item.occupationalLabelArr = item.occupationalLabel ? item.occupationalLabel.split('，') : [];
        let workDesc =  this.workFormat(item.workExperience) ? this.workFormat(item.workExperience) + ' / '  : '';
        let edcDesc = this.edcFormat(item.education) ?  this.edcFormat(item.education) : '';
        let age = item.age ? ' / ' + item.age + '岁' : '';
        item.descriptions = workDesc + edcDesc + age;
    },
    // 性别字典翻译
    sexFormat(row, column) {
      return this.selectDictLabel(this.sexOptions, row.sex);
    },
    workFormat(val){
      return this.selectDictLabel(this.workExperienceArr, val);
    },
    edcFormat(val){
      return this.selectDictLabel(this.educationArr, val);
    },
    /** 列出所有简历介绍 */
    listAllResume(){
      getAllResume().then(response => {
        this.resumeOptions = response.data
        if(response.data.length == 0 ){
          console.log("数组大小为0")
        }
      });
    },
    /** 切换用工单位触发 */
    changeCompany(){
      this.form.jobId = ''
      var companyId = this.form.companyId
      this.findJobInfoByCompanyId(companyId)
    },
    /** 根据企业获取岗位信息 */
    findJobInfoByCompanyId(companyId){
      getJobInfoByCompanyId(companyId).then(response => {
        this.jobOptions = response.data
        if(response.data.length == 0 ){
          console.log("数组大小为0")
        }
      });
    },
    /** 获取公司列表 */
    getAllCompanysInfo(){
      getAllCompanysInfo().then(response => {
        this.companyOptions = response.data
        if(response.data.length == 0 ){
          console.log("数组大小为0")
        }
      });
    },
    /** 查询求职信息列表 */
    getList() {
      this.loading = true;
      listInterview(this.queryParams).then(response => {
        this.interviewList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 求职类型字典翻译
    interviewTypeFormat(row, column) {
      return this.selectDictLabel(this.interviewTypeOptions, row.interviewType);
    },
    // 简历状态字典翻译
    resumeStatusFormat(row, column) {
      return this.selectDictLabel(this.resumeStatusOptions, row.resumeStatus);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        interviewId: null,
        resumeId: null,
        companyId: null,
        jobId: null,
        interviewType: null,
        resumeStatus: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.interviewId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加求职信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const interviewId = row.interviewId || this.ids
      getInterview(interviewId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改求职信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.interviewId != null) {
            updateInterview(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInterview(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const interviewIds = row.interviewId || this.ids;
      // this.$confirm('是否确认删除求职信息编号为"' + interviewIds + '"的数据项?', "警告", {
        this.$confirm('是否确认删除该项数据?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInterview(interviewIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有求职信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportInterview(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
<style lang="scss" scoped>
.introduction{
  padding-left: 20px;
  display: flex;
}
.introduction .name{
  font-size: 20px;
  font-weight: bold;
  margin-right: 20px;
  margin-left: 40px;
  width: 80px;
}
.introduction .experience{
  font-size: 16px;
  /* color: #666; */
}
.introduction .notes{
  color: #999;
  margin-top: 5px;
}
.notes ul li{
  float: left;
  margin-right: 20px;
  margin-bottom: 10px;
  font-size: 12px;
  background: #fff;
  border: 1px solid #c0c4cc;
  line-height: 21px;
  padding: 0 8px;
  border-radius: 10px;
}
</style>